
const defaultThreshold = 128;
var arrayBitmap;

function pageStartData() {
  return '1F200088';
}

function pageEndData() {
  return [31, 40, 0, 136];
}

function pageWidthData(_0x39b1a3) {
  _0x39b1a3 = Math.floor((_0x39b1a3 + 7) / 8);

  if (_0x39b1a3 >= 192) {
    return [31, 39, 2, 192 | _0x39b1a3 >> 8, _0x39b1a3 & 255, 136];
  } else {
    return [31, 39, 1, _0x39b1a3, 136];
  }
}

function pageHeightData(_0x29243f) {
  if (_0x29243f > 16383) {
    return [31, 38, 3, 192, 16383 | _0x29243f >> 8, _0x29243f & 255, 136];
  } else if (_0x29243f >= 192) {
    return [31, 38, 2, 192 | _0x29243f >> 8, _0x29243f & 255, 136];
  } else {
    return [31, 38, 1, _0x29243f, 136];
  }
}

function settingGapTypeData(_0x5b9ddd) {
  return [31, 66, 1, _0x5b9ddd, 136];
}

function settingGapLengthData(_0x2a41cf) {
  if (_0x2a41cf > 16383) {
    return [31, 69, 3, 192 | _0x2a41cf >> 16, _0x2a41cf >> 8, _0x2a41cf & 255, 136];
  } else if (_0x2a41cf >= 192) {
    return [31, 69, 2, 192 | _0x2a41cf >> 8, _0x2a41cf & 255, 136];
  } else {
    return [31, 69, 1, _0x2a41cf, 136];
  }
}

function settingStrengthData(_0xd651f1) {
  return [31, 67, 1, _0xd651f1, 136];
}

function settingSpeedData(_0x4c726b) {
  return [31, 68, 1, _0x4c726b, 136];
}

function arrayWithImage(_0x3b92d3, _0x20343f, _0x5307b6, _0x4256c6, _0x37192f, _0x1feb4e, _0x3acdfc, _0x5132a2, _0x190737) {
  arrayBitmap = new Array();
  pushPackageWithData(pageWidthData(_0x4256c6));
  pushPackageWithData(pageHeightData(_0x37192f));

  if (_0x1feb4e >= 0) {
    pushPackageWithData(settingGapTypeData(_0x1feb4e));
  }

  if (_0x1feb4e != 0) {
    pushPackageWithData(settingGapLengthData(_0x3acdfc));
  }

  if (_0x5132a2 > 0) {
    pushPackageWithData(settingStrengthData(_0x5132a2 - 1));
  }

  if (_0x190737 > 0) {
    pushPackageWithData(settingSpeedData(_0x190737 - 1));
  }

  parsePixelDatas(_0x3b92d3, _0x4256c6, _0x37192f);

  arrayBitmap.unshift(pageStartData());

  pushPackageWithData(pageEndData());
  return arrayBitmap;
}

function parsePixelDatas(_0xe8d71c, _0x29751e, _0x1d45d9) {
  var _0x171a0f;

  var _0xab4c04 = 0;

  var _0x20aa5b = Math.floor((_0x29751e + 7) / 8);

  for (var _0xad25dd = 0; _0xad25dd < _0x1d45d9; _0xad25dd++) {
    var _0x1836f7 = [_0x20aa5b];

    for (var i = 0; i < _0x20aa5b; i++) {
      _0x1836f7[i] = 0;
    }

    var _0x454687 = 0;
    var _0x43569a = 0;
    var _0x3ebd9a = 0;
    var _0x5d9620 = 0;
    var _0x41bb20 = 0;
    var _0xaa8a41 = 0;
    var _0x172fef = 0;
    var _0x24ade9 = 0;

    for (var _0xf281e0 = 0; _0xf281e0 < _0x29751e; _0xf281e0++) {
      var _0x10a987 = _0xf281e0 % 8;

      if (_0x10a987 == 0) {
        _0x454687 = 0;
        _0x43569a = 0;
        _0x3ebd9a = 0;
        _0x5d9620 = 0;
        _0x41bb20 = 0;
        _0xaa8a41 = 0;
        _0x172fef = 0;
        _0x24ade9 = 0;
      }

      var _0x2f351b = (_0x29751e * _0xad25dd + _0xf281e0) * 4;

      var _0x354de6 = _0xe8d71c[_0x2f351b + 0];
      var _0x26e16a = _0xe8d71c[_0x2f351b + 1];
      var _0x526177 = _0xe8d71c[_0x2f351b + 2];
      var _0x53787a = _0xe8d71c[_0x2f351b + 3];

      if (_0x53787a > 0) {
        var _0xec5886 = _0x354de6 * 0.3 + _0x26e16a * 0.59 + _0x526177 * 0.11;

        if (_0xec5886 <= 128) {
          if (_0x10a987 == 0) {
            _0x454687 = 128;
          } else if (_0x10a987 == 1) {
            _0x43569a = 64;
          } else if (_0x10a987 == 2) {
            _0x3ebd9a = 32;
          } else if (_0x10a987 == 3) {
            _0x5d9620 = 16;
          } else if (_0x10a987 == 4) {
            _0x41bb20 = 8;
          } else if (_0x10a987 == 5) {
            _0xaa8a41 = 4;
          } else if (_0x10a987 == 6) {
            _0x172fef = 2;
          } else if (_0x10a987 == 7) {
            _0x24ade9 = 1;
          }
        }
      }

      if (_0x10a987 == 7 || _0xf281e0 == _0x29751e - 1) {
        var _0x2f351b = Math.floor(_0xf281e0 / 8);

        var _0x28e757 = _0x454687 | _0x43569a | _0x3ebd9a | _0x5d9620 | _0x41bb20 | _0xaa8a41 | _0x172fef | _0x24ade9;

        _0x1836f7[_0x2f351b] = _0x28e757;
      }
    }

    var _0x1f07ab = _0x20aa5b - 1;

    for (; _0x1f07ab >= 0; _0x1f07ab--) {
      if (_0x1836f7[_0x1f07ab] != 0) {
        break;
      }
    }

    var _0x567b56 = 0;

    for (; _0x567b56 < _0x1f07ab; _0x567b56++) {
      if (_0x1836f7[_0x567b56] != 0) {
        break;
      }
    }

    var _0x226e71 = _0x1f07ab + 1 - _0x567b56;

    var _0x34bb89 = [_0x226e71 + 4];
    _0x34bb89[0] = 31;
    _0x34bb89[1] = 43;
    _0x34bb89[2] = _0x567b56;
    _0x34bb89[3] = _0x226e71;

    if (_0x226e71 > 0) {
      for (var _0x2010ae = 0; _0x2010ae < _0x226e71; _0x2010ae++) {
        _0x34bb89[_0x2010ae + 4] = _0x1836f7[_0x2010ae + _0x567b56];
      }
    }

    if (_0x171a0f == null) {
      _0x171a0f = _0x34bb89;
      pushPackageWithData(_0x34bb89);
    } else {
      if (_0x34bb89.toString() == _0x171a0f.toString() && _0xab4c04 < 150) {
        _0xab4c04++;
      } else {
        if (_0xab4c04 > 0) {
          var _0x480dc1 = [31, 46, _0xab4c04 - 1];
          pushPackageWithData(_0x480dc1);
          _0xab4c04 = 0;
        }

        _0x171a0f = _0x34bb89;
        pushPackageWithData(_0x34bb89);
      }
    }
  }

  if (_0xab4c04 > 0) {
    var _0x480dc1 = [31, 46, _0xab4c04 - 1];
    pushPackageWithData(_0x480dc1);
  }
}

function pushPackageWithData(_0x175870) {
  var _0x3569aa = new Array();

  for (var i = 0; i < _0x175870.length; i++) {
    var _0x43e73e = parseInt(_0x175870[i]);

    var _0x1779fb = _0x43e73e.toString(16);

    if (_0x1779fb.length % 2 == 1) {
      var _0x5cb906 = "0" + _0x1779fb;

      _0x3569aa.push(_0x5cb906);
    } else {
      _0x3569aa.push(_0x1779fb);
    }
  }

  arrayBitmap.push(_0x3569aa.join(""));
}

module.exports = {
  "arrayWithImage": arrayWithImage
};